package com.haoshuang.zhouzhoubang.ui.page.study.train.child

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.TrainArticleBean
import com.haoshuang.zhouzhoubang.model.bean.TrainLabelBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.ResponseBean
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class TrainExamArticleViewModel : BaseViewModel() {

    /**
     * 获取培训考试文章列表
     */
    val getTrainExamArticleListData = StatefulMutableLiveData<ResponseBean<MutableList<TrainArticleBean>>>()
    fun getTrainExamArticleList(type: String, page: Int) = netRequest {
        start { getTrainExamArticleListData.value = StateData.Loading }
        request { ApiRepo.getTrainExamArticleList(type, page)  }
        success { getTrainExamArticleListData.value = StateData.Success(it) }
        error { code, msg ->
            getTrainExamArticleListData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 获取培训文章分类
     */
    val getTrainLabelData = StatefulMutableLiveData<ResponseBean<MutableList<TrainLabelBean>>>()
    fun getTrainLabel() = netRequest {
        start { getTrainLabelData.value = StateData.Loading }
        request { ApiRepo.getTrainLabel()  }
        success { getTrainLabelData.value = StateData.Success(it) }
        error { code, msg ->
            getTrainLabelData.value = StateData.Error(code, msg)
        }
    }

}